package com.erp.myAdapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.erp.activity.MainKActivity;
import com.erp.bean.Userdataonebean;
import com.erp.R;

import java.util.List;

/**
 * Created by Administrator on 2016/11/10/010.
 * 作者：刘洋
 */
public class Listuserdataadapter extends BaseAdapter {
    private List<Userdataonebean> mlistdata;
    private Context mcontext;
    private LayoutInflater minflater;
    public Listuserdataadapter(List<Userdataonebean> listdata, Context context){
        super();
        this.mlistdata=listdata;
        this.mcontext=context;
        this.minflater=LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return mlistdata.size();
    }

    @Override
    public Object getItem(int i) {
        return mlistdata.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder vh=null;
        if(view==null){
            vh=new ViewHolder();
            view=minflater.inflate(R.layout.lv_namedata_item,null);
            vh.tv0= (TextView) view.findViewById(R.id.tv_data_0);
            vh.tv1= (TextView) view.findViewById(R.id.tv_data_1);
            vh.tv2= (TextView) view.findViewById(R.id.tv_data_2);
            vh.tv3= (TextView) view.findViewById(R.id.tv_data_3);
            vh.tv4= (TextView) view.findViewById(R.id.tv_data_4);
            vh.tv5= (TextView) view.findViewById(R.id.tv_data_5);
            vh.tv6= (TextView) view.findViewById(R.id.tv_data_6);
            vh.tv7= (TextView) view.findViewById(R.id.tv_data_7);
            vh.tvCTeFu= (TextView) view.findViewById(R.id.tvCTeFu);
            vh.LlCTeFu= (LinearLayout) view.findViewById(R.id.LlCTeFu);

            vh.tv_production_0= (TextView) view.findViewById(R.id.tv_production_0);
            vh.tv_production_1= (TextView) view.findViewById(R.id.tv_production_1);
            vh.tv_production_2= (TextView) view.findViewById(R.id.tv_production_2);
            vh.tv_production_3= (TextView) view.findViewById(R.id.tv_production_3);
            vh.tv_production_4= (TextView) view.findViewById(R.id.tv_production_4);
            vh.tv_production_5= (TextView) view.findViewById(R.id.tv_production_5);
            vh.tv_production_6= (TextView) view.findViewById(R.id.tv_production_6);
            vh.tv_production_7= (TextView) view.findViewById(R.id.tv_production_7);
            vh.tvTeFu= (TextView) view.findViewById(R.id.tvTeFu);
            vh.LlTeFu= (LinearLayout) view.findViewById(R.id.LlTeFu);
            vh.LlKehuGuanli= (LinearLayout) view.findViewById(R.id.LlKehuGuanli);
            vh.LlDingdanChaxun= (LinearLayout) view.findViewById(R.id.LlDingdanChaxun);

            view.setTag(vh);
        }else{
            vh= (ViewHolder) view.getTag();
        }

        Userdataonebean data=new Userdataonebean();
        data=mlistdata.get(i);
//        if(data.crm_oid != "") {
            vh.LlKehuGuanli.setVisibility(View.VISIBLE);
            vh.LlDingdanChaxun.setVisibility(View.GONE);
            settv(data.customer_name, vh.tv0);
            settv(data.ps_name, vh.tv1);
            settv(data.shop_name, vh.tv2);
            settv(data.dizhi.toString(), vh.tv3);
            settv(data.customer_tel, vh.tv4);
            String[] xiaoshou = data.xiaoshouyuan_name.split("<br />");
            StringBuffer xiaoshouyuan = new StringBuffer("");
            for (int j = 0; j < xiaoshou.length; j++) {
                if (j == xiaoshou.length - 1) {
                    xiaoshouyuan.append(xiaoshou[j]);
                } else {
                    xiaoshouyuan.append(xiaoshou[j]);
                    xiaoshouyuan.append("\n");
                }
            }
            settv(xiaoshouyuan.toString(), vh.tv5);
            String[] sheji = data.designer_name.split("<br />");
            StringBuffer shejishi = new StringBuffer("");
            for (int j = 0; j < sheji.length; j++) {
                if (j == sheji.length - 1) {
                    shejishi.append(sheji[j]);
                } else {
                    shejishi.append(sheji[j]);
                    shejishi.append("\n");
                }
            }
            settv(shejishi.toString(), vh.tv6);
            settv(data.crm_c_contract_num, vh.tv7);
            if(MainKActivity.Companion.getZhuanMaiDianid().equals("0") && !data.o_special_service_cat.equals("")){
                vh.LlCTeFu.setVisibility(View.VISIBLE);
                settv(data.o_special_service_cat, vh.tvCTeFu);
            }else{
                vh.LlCTeFu.setVisibility(View.GONE);
            }
//        }else {
//            vh.LlKehuGuanli.setVisibility(View.GONE);
//            vh.LlDingdanChaxun.setVisibility(View.VISIBLE);
//            settv(data.onum, vh.tv_production_0);
//            settv(data.ot_name, vh.tv_production_1);
//            settv(data.content_description, vh.tv_production_2);
//            settv(data.customer, vh.tv_production_3);
//            settv(data.tel, vh.tv_production_4);
//            settv(data.contract_num, vh.tv_production_5);
//            settv(data.shop_name, vh.tv_production_6);
//            if (data.special_status.equals("5")) {
//                settv("已取消", vh.tv_production_7);
//            } else if (data.special_status.equals("0")) {
//                settv("", vh.tv_production_7);
//            }
//            if(MainKActivity.Companion.getZhuanMaiDianid().equals("0") && !data.special_service_cat.equals("")){
//                vh.LlTeFu.setVisibility(View.VISIBLE);
//                settv(data.special_service_cat,vh.tvTeFu);
//            }else{
//                vh.LlTeFu.setVisibility(View.GONE);
//            }
//        }
        Log.d("special_service_cat", data.special_service_cat+"====="+data.special_service_cat.equals(""));
        return view;
    }
    public void settv(String s,TextView tv){
        if(s.equals("null")){
            tv.setText("");
        }else{
            tv.setText(s);
        }
    }
    private class ViewHolder{
        TextView tv0,tv1,tv2,tv3,tv4,tv5,tv6,tv7,
                tv_production_0,tv_production_1,tv_production_2,tv_production_3,tv_production_4,tv_production_5,tv_production_6,tv_production_7,tvTeFu,tvCTeFu;
        LinearLayout LlTeFu,LlKehuGuanli,LlDingdanChaxun,LlCTeFu;
    }
}
